﻿using INTEX.DataBase;
using INTEX.DataBase.Tools;
using ReflectionStudio.Core;
using ReflectionStudio.Core.Events;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.IO;
using System.Linq;
using System.Windows;
namespace WPFExcelReport
{
    public partial class ITXEXRPT
    {
        public void YGRVK13LIST(DataSet db)
        {
            int x = 4, y = 1;
            string VKPPOSTYP = "";
            DataTable dtOutput = new DataTable();
            try
            {
                #region======Title===========
                exAgent.SetCellValue(3, 1, "类型"); dtOutput.Columns.Add("VKPPOSTYP", typeof(System.String));
                exAgent.SetCellValue(3, 2, " "); dtOutput.Columns.Add("VKPAUFKRS", typeof(System.String));
                exAgent.SetCellValue(3, 3, "PPO"); dtOutput.Columns.Add("VKPAUFLFD", typeof(System.String));
                exAgent.SetCellValue(3, 4, ""); dtOutput.Columns.Add("VKPAUFPOS", typeof(System.String));
                exAgent.SetCellValue(3, 5, "客户"); dtOutput.Columns.Add("KDKUNDNA", typeof(System.String));
                exAgent.SetCellValue(3, 6, "品种"); dtOutput.Columns.Add("VKPART", typeof(System.String));
                exAgent.SetCellValue(3, 7, "色号"); dtOutput.Columns.Add("VKPFARBE", typeof(System.String));
                exAgent.SetCellValue(3, 8, "报价要素"); dtOutput.Columns.Add("VKCOM", typeof(System.String));
                exAgent.SetCellValue(3, 9, "强力标准"); dtOutput.Columns.Add("STRENGTH", typeof(System.String));
                exAgent.SetCellValue(3, 10, "预计重量"); dtOutput.Columns.Add("VKPMENGE1", typeof(System.Decimal));
                exAgent.SetCellValue(3, 11, "单位"); dtOutput.Columns.Add("VKPMEEH", typeof(System.String));
                exAgent.SetCellValue(3, 12, "联系人"); dtOutput.Columns.Add("VKKANSPRECH", typeof(System.String));
                exAgent.SetCellValue(3, 13, "价格"); dtOutput.Columns.Add("VKPPREISX", typeof(System.Decimal));
                exAgent.SetCellValue(3, 14, "PUM"); dtOutput.Columns.Add("PUM", typeof(System.String));
                exAgent.SetCellValue(3, 15, "询价日期"); dtOutput.Columns.Add("VKKBESTDAT", typeof(System.String));
                exAgent.SetCellValue(3, 16, "报价日期"); dtOutput.Columns.Add("VKPNEUDAT", typeof(System.String));
                exAgent.SetCellValue(3, 17, "拖期天数"); dtOutput.Columns.Add("DELAYDAYS", typeof(System.Decimal));
                exAgent.SetCellValue(3, 18, "有效期"); dtOutput.Columns.Add("VKKGLTBIS", typeof(System.String));
                #endregion

                #region======ConvertData===

                var qGW = from GW in db.Tables["VKPOS"].AsEnumerable()
                          group GW by new
                          {
                              PT = GW["VKPPOSTYP"].ToString(),
                          }
                              into g
                              select new
                              {
                                  KEY = g.Key,
                              };
                foreach (var GW in qGW)
                {
                    VKPPOSTYP = GW.KEY.PT;
                    exAgent.SetCurrentSheet("YGRVK13LIST");
                    exAgent.CopySheet(VKPPOSTYP);
                    DataRow[] rows = db.Tables["VKPOS"].Select("VKPPOSTYP='" + VKPPOSTYP + "'");
                    DataTable dtSoruce = rows.CopyToDataTable();
                    dtOutput.Clear();
                    dtOutput.Merge(dtSoruce, false, MissingSchemaAction.Ignore);
                    foreach (DataRow rx in dtOutput.Rows)
                    {
                    }
                #endregion

                    #region====Excel==========
                    int count = dtOutput.Rows.Count;
                    exAgent.RangeCopy(4, 50, 5, 4 + count);
                    exAgent.DataTableToExcel(dtOutput, x, 1);
                    //exAgent.SetCellValue(1, 1, 1);
                    //exAgent.BatchConvert2Number(5, 16, count + 3, 19);
                    exAgent.SetCellValue(1, 1, " ");
                    #endregion
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            finally
            {
                EventDispatcher.Instance.RaiseStatus("完成", StatusEventType.StopProgress);
            }
        }

    }
}